//
//  MovieListViewController.m
//  豆瓣_精简版
//
//  Created by dllo on 15/11/6.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "MovieListViewController.h"
#import "MovieTableViewController.h"
#import "MovieCollectionViewController.h"
@interface MovieListViewController ()

@property(nonatomic,retain)MovieCollectionViewController *collectionVC;
@property(nonatomic,retain)MovieTableViewController *tableVC;
@property(nonatomic,assign)BOOL isSelected;
@property(nonatomic,retain)UIImage *rightImage1;
@end

@implementation MovieListViewController

- (void)dealloc
{
    [_tableVC release];
    [_collectionVC release];
    [_rightImage1 release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"电影";
    
    self.collectionVC = [[MovieCollectionViewController alloc]init];
    self.tableVC = [[MovieTableViewController alloc]init];
    
    
    [self addChildViewController:self.collectionVC];
    [self addChildViewController:self.tableVC];
    
    [self.view addSubview:self.collectionVC.view];
    [self.view addSubview:self.tableVC.view];
    
    [self.tableVC release];
    [self.collectionVC release];
    
    self.rightImage1 = [UIImage imageNamed:@"btn_nav_collection@2x.png"];
    self.rightImage1 = [self.rightImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:self.rightImage1 style:UIBarButtonItemStyleDone target:self action:@selector(buttonAction:)];
    
    self.isSelected = NO;
    
}


- (void)buttonAction:(UIBarButtonItem *)but{

    if (self.isSelected == NO) {
        
        //        [self.view bringSubviewToFront:self.collectionVC.view];
        [UIView transitionFromView:self.tableVC.view toView:self.collectionVC.view duration:0.5 options:UIViewAnimationOptionTransitionNone completion:^(BOOL finished) {
            
            
        }];
        UIImage *rightImage2 = [UIImage imageNamed:@"btn_nav_list@2x.png"];
        rightImage2 = [rightImage2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        self.navigationItem.rightBarButtonItem.image = rightImage2;
        
        [self.collectionVC.myCollectionView reloadData];
        
        
    }else{
        
        //        [self.view bringSubviewToFront:self.listVC.view];
        [UIView transitionFromView:self.collectionVC.view toView:self.tableVC.view duration:0.5 options:UIViewAnimationOptionTransitionNone completion:^(BOOL finished) {
            
            
        }];
        self.navigationItem.rightBarButtonItem.image = self.rightImage1;
    }
    self.isSelected = !self.isSelected;
 
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
